#include <head.h>
int main(int argc, char *argv[])
{
    int fd = open("merged.txt", O_RDWR | O_CREAT, 0666);
    if (fd < 0)
    {
        printf("无法打开输出文件\n");
        return 1;
    }

    FILE *outfile = fdopen(fd, "w+");
    if (outfile == NULL)
    {
        printf("无法打开输出文件\n");
        close(fd);
        return 1;
    }

    for (int i = 1; i < argc; i++)
    {
        FILE *infile = fopen(argv[i], "r");

        if (infile == NULL)
        {
            printf("无法打开输入文件 %s\n", argv[i]);
            fclose(outfile);
            return 1;
        }

        int c;
        while ((c = fgetc(infile)) != EOF)
        {
            fputc(c, outfile);
        }
        fclose(infile);
    }
    fclose(outfile);
    return 0;
}